--理为人存
local liweirenchun = fk.CreateSkill {
    name = "mcdh_liweirenchun",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

liweirenchun:addEffect( fk.Damaged,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) or not data.from then return false end
        local damage = 0;
        player.room.logic:getActualDamageEvents(3, function(evt)
            if evt.data[1].from == data.from then
                damage = damage + evt.data[1].damage
                return true
            end
            return false
        end, Player.HistoryTurn)
        if damage - data.damage >= 2 then return false end
        return damage >= 2
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local choiceList = { "#mcdh_liweirenchun-recover", "#mcdh_liweirenchun-maxhands" }
        if not data.to:isWounded()  or data.to.dead then table.remove(choiceList, 1) end
        local choice = room:askForChoice(
                player,
                choiceList,
                self.name,
                "#mcdh_liweirenchun-choise:" .. data.to.id .. ":" .. data.from.id,
                false
        )
        if choice == "#mcdh_liweirenchun-recover" then
            room:recover {
                who = data.to,
                recoverBy = player,
                num = 1,
                skillName = self.name
            }
        elseif choice == "#mcdh_liweirenchun-maxhands" then
            room:addPlayerMark(data.from, "MinusMaxCards-turn", 1)
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_liweirenchun"] = "存智",
    [":mcdh_liweirenchun"] = "『理为人存』<br>锁定技，当一名角色于本回合造成第2点伤害后，你选择一项：1.令受伤角色回复1点体力；2.令伤害来源本回合手牌上限-1。",
    ["#mcdh_liweirenchun-choise"] = "理为人存:令 %src 回复1点体力，或令 %dest 本回合手牌上限-1",
    ["#mcdh_liweirenchun-recover"] = "回复体力",
    ["#mcdh_liweirenchun-maxhands"] = "减少手牌上限"
}

return liweirenchun